package com.ubao.network.manager;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.ubao.R;


 

public class NetWorkNtfyManager {
	
	private Context mContext;
	
	public  static int  NOTIFY_ID = 545099885;
	
	public static NetWorkNtfyManager instance;
	
	private NotificationManager mNm;
	
	private NetWorkNtfyManager(Context context){
		mContext = context;
	}
	
	public static NetWorkNtfyManager getInstance(){
		return instance;
	}
	
	public static NetWorkNtfyManager getInstance(Context context){
		if(instance == null){
			instance = new NetWorkNtfyManager(context);
		}
		return instance;
	}
	
	//是否正在显示
	private boolean isShow = false;
	
	//是否需要显示,app pause时候不显示
	private boolean needShow = true;
	
    public  void sendNotify(String msg){
    	
    	if(!needShow){
    		return;
    	}
    	
    	if(isShow){
    		return;
    	}else{
    		isShow = true;
    	}
    	
    	mNm = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
 
        String tickerText = msg;
        PendingIntent contentIntent = PendingIntent.getActivity(mContext , 0,
                new Intent(), 0);
        
        // construct the Notification object.
        Notification notif = new Notification(R.drawable.triangle, tickerText,
                System.currentTimeMillis());
        notif.flags |=  Notification.FLAG_AUTO_CANCEL;
        // Set the info for the views that show in the notification panel.
        notif.setLatestEventInfo(mContext, "东方财富通", tickerText, contentIntent);

        mNm.notify(NOTIFY_ID,notif);
        mNm.cancel(NOTIFY_ID);

        new Timer().schedule(new TimerTask() {
    		@Override
    		public void run() {
    			isShow = false;
    		}
    	}, 3000);

    }
     
    public void setShowFlag(boolean b){
 
		this.needShow = b;
    }
 
	
}
